#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std ;

const int maxn = 210 , INF = 1e9;

int n , m , Q ; //Q是询问次数
int d[maxn][maxn] ;//邻接矩阵

void floyd() {
    for(int k = 1 ; k <=n ; k++){
        for (int i = 1; i <= n ; ++i) {
            for (int j = 1; j <=n ; ++j) {
                d[i][j] = min(d[i][j] , d[i][k] + d[k][j]); //尝试着把每一个点加进来，如果加进来的点对某两点之间的距离有影响的话就更新
            }
        }
    }
}

int main() {

    scanf("%d%d%d" , &n , &m , &Q);

    //初始化邻接矩阵
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m ; ++j) {
            if(i == j) {
                d[i][j] = 0 ;
            }else{
                d[i][j] = INF ;
            }
        }
    }

    while(m--) {
        int a , b , w;
        scanf("%d%d%d" , &a , &b , &w);
        d[a][b] = min(d[a][b] , w);//消去多重边
    }

    floyd();

    while(Q--){
        int a , b ;
        scanf("%d%d" , &a , &b);
        if(d[a][b] > INF / 2){
            puts("impossible");
        }else{
            printf("%d\n" , d[a][b]);
        }
    }

    return 0 ;
}